<?php

/*
	info: 资讯管理
	date: 2011-11-28
*/

if (!defined('ADMIN_WEBINROOT'))
{
	header("HTTP/1.0 404 Not Found");
	exit();
}

require WEBFILEPATH.'/include/category.class.php';
$webglobal['file_news'] = array();

$webglobal['file_news']['channeltype'] = array(
	1 => '普通文章',
	2 => '图片集'
);

$webglobal['file_news']['arcrank'] = array(
	0  => '开放浏览',
	-1 => '待审核稿件',
	1  => '注册会员',
	2  => '认证会员',
);

$categoryDataModel = CategoryDataModel::factory('news', array('cache' => true));
$webglobal['file_news']['category'] = $categoryDataModel->formatCategoryOption(0,0);

//添加
if ($webglobal['mode']=='newsadd')
{
	if (global_CheckSubmit('adminsubmit'))
	{
		global_CheckPost(
				array(
					array('news_category_id,','int','isset($webglobal[\'file_news\'][\'category\'][@])','请选择资讯分类',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('weight,','int','','',0,0),
					array('index,','int','','',0,0),
					array('ishot,','int','','',0,0),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM']))
		{
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			admin_CheckFromForm(ADMIN_WEBURLPATH."/index.php?mode=news");

			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);
			$webglobal['CPD']['edittime'] = $webserver['timestamp'];
			$tempnewsid = $db->Insert('news', '', TRUE);

			if ($webglobal['CPP']['index'] == 1)
			{
				//显示到首页的后续更新操作
			}

			//删除站点公告缓存
			cache_GetNotice($categoryDataModel, true);
			cache_GetShowIndexNews($categoryDataModel, true);

			admin_AddLog("添加资讯|id: {$tempnewsid}; classid: {$webglobal['CPP']['news_category_id']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('资讯添加成功。', ADMIN_WEBURLPATH."/index.php?mode=news");
		}
	}
	else
	{
		admin_StartFromForm();
	}
}

//编辑
elseif ($webglobal['mode']=='newsedit')
{
	$webrequest['editid'] = isset($webrequest['editid']) ? intval($webrequest['editid']) : 0;
	if ($webrequest['editid'] <= 0)
	{
		admin_ShowMessage('不存在该资讯。', '', 'BACK');
	}
	$webglobal['file_news']['editinfo'] = $db->GetOne("SELECT * FROM {$webconfig['dbpre']}news WHERE id='{$webrequest['editid']}'");
	if (!$webglobal['file_news']['editinfo'])
	{
		admin_ShowMessage('不存在该资讯。', '', 'BACK');
	}

	if (global_CheckSubmit('adminsubmit'))
	{
		global_CheckPost(
				array(
					array('news_category_id,','int','isset($webglobal[\'file_news\'][\'category\'][@])','请选择资讯分类',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('weight,','int','','',0,0),
					array('index,','int','','',0,0),
					array('ishot,','int','','',0,0),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM']))
		{
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		}
		else
		{
			admin_CheckFromForm(ADMIN_WEBURLPATH."/index.php?mode=news&{$webrequest['gourl']}");

			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);
			$webglobal['CPD']['edittime'] = $webserver['timestamp'];
			$db->Update('news', '', "id='{$webrequest['editid']}'");

			if ($webglobal['CPP']['index']==1 || $webglobal['file_news']['editinfo']['index']==1)
			{
				//首页处理
			}

			//删除站点公告缓存
			cache_GetNotice($categoryDataModel, true);
			cache_GetShowIndexNews($categoryDataModel, true);
			cache_GetHotNews($categoryDataModel, true);

			admin_AddLog("修改资讯|id: {$webrequest['editid']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('资讯修改成功。', ADMIN_WEBURLPATH."/index.php?mode=news&{$webrequest['gourl']}");
		}
	}
	else
	{
		$webglobal['file_news']['gourlencode'] = urlencode($webrequest['gourl']);
		$webglobal['file_news']['editinfo']['showtime_show'] = global_FormatTime($webglobal['file_news']['editinfo']['showtime'], 'FD');
		admin_StartFromForm();
	}

//批量更改
} elseif ($webglobal['mode']=='newsup') {

	if (!global_CheckCome())
	{
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	global_CheckPost(
				array(
					array('checkid[]','int','',''),
					array('access','str','','',0,'update'),
			));

	$tempdelstr = '';
	if ($webglobal['CPP']['access'] == 'delete') {
		if (!empty($webglobal['CPP']['checkid'])) {
			$tempdelstr = implode(',', $webglobal['CPP']['checkid']);
			$db->Delete('news', 'id IN ('.$db->BuildInSql($webglobal['CPP']['checkid']).')');
			$tempdelstr = implode(',', $webglobal['CPP']['checkid']);
		}
	}

	$templogmsg = '';

	if (!empty($tempdelstr))
	{
		$templogmsg .= (empty($templogmsg) ? '' : '; ')."del: {$tempdelstr}";
	}

	if (empty($templogmsg))
	{
		admin_ShowMessage("没有任何条目被修改，系统自动返回。", ADMIN_WEBURLPATH."/index.php?mode=content&{$webrequest['gourl']}");
	}

	admin_AddLog("批量删除资讯|{$templogmsg}");
	admin_ShowMessage('批量批量删除资讯成功。', ADMIN_WEBURLPATH."/index.php?mode=content&{$webrequest['gourl']}");

} elseif ($webglobal['mode']=='contentadd') {
	$webrequest['root'] = isset($webrequest['root']) ? intval($webrequest['root']) : 0;
	if (!$webrequest['root'] || !array_key_exists($webrequest['root'], $webconfig['newsTopType'])) {
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	$webglobal['file_news']['rootCategory'] = $categoryDataModel->getItem($webrequest['root']);

	//$webglobal['file_news']['channelName'] = $webglobal['file_news']['channeltype'][$webrequest['channel']];
	$webglobal['file_news']['class'] = $categoryDataModel->getCategoryOptionByChannel(1, $webrequest['root']);
	//$webglobal['file_news']['class'] = $categoryDataModel->formatCategoryOption($webrequest['root'], 0);
	//
	if (global_CheckSubmit('adminsubmit')) {
		global_CheckPost(
				array(
					array('news_category_id,','int','','请指定文档的栏目！',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM'])) {
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		} else {
			
			//admin_CheckFromForm(ADMIN_WEBURLPATH."/index.php?mode=news");
			//$category = $webglobal['file_news']['class'][$webglobal['CPD']['news_category_id']];

			if(!$categoryDataModel->checkChannel($webglobal['CPD']['news_category_id'], 1)) {
				admin_ShowMessage("你所选择的栏目与当前模型不相符，请选择白色的选项！", '', 'BACK');
				exit();
			}
			$webglobal['CPD']['flag'] = isset($webrequest['flags']) ? implode(',', $webrequest['flags']) : '';
			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);

			$webglobal['CPD']['edittime'] = $webserver['timestamp'];

			$webglobal['CPD']['title'] = preg_replace("#\"#", '＂', $webglobal['CPD']['title']);
			$webglobal['CPD']['title'] = global_CutStrR($webglobal['CPD']['title'], 100);
			if ($webrequest['shorttitle'] == '') {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['title'],36);
			} else {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['shorttitle'],36);
			}
			$webglobal['CPD']['color'] =  global_CutStrR($webrequest['color'],7);
			$webglobal['CPD']['writer'] =  global_CutStrR($webrequest['writer'],20);
			$webglobal['CPD']['from'] =  global_CutStrR($webrequest['from'],30);
			if ($webrequest['picname'] != '') {
				$webglobal['CPD']['litpic'] = str_replace(WEBURLPATH, '', $webrequest['picname']);
			}

			if ($webrequest['description'] == '') {
				//自动摘要
				$webglobal['CPD']['description'] = global_CutStr(SpHtml2Text($webglobal['CPD']['content']), 200);
				$webglobal['CPD']['description'] = trim(preg_replace('/#p#|#e#/','',$webglobal['CPD']['description']));
				$webglobal['CPD']['description'] = addslashes($webglobal['CPD']['description']);
			} else {
				$webglobal['CPD']['description'] =  global_CutStrR($webrequest['description'], 200);
			}
			$webglobal['CPD']['keywords'] =  global_CutStrR($webrequest['keywords'], 60);

			$webrequest['sortup'] = isset($webrequest['sortup']) ? intval($webrequest['sortup']) : 0;
			$webglobal['CPD']['sortrank'] = AddDay($webglobal['CPD']['showtime'], $webrequest['sortup']);
			$webglobal['CPD']['sortup'] = $webrequest['sortup'];
			$webglobal['CPD']['click'] = intval($webrequest['click']);
			$webglobal['CPD']['arcrank'] = intval($webrequest['arcrank']);

			$webglobal['CPD']['dutyadmin'] = $user['adminuid'];
			$webglobal['CPD']['channel'] = 1;
			$webglobal['CPD']['brand_id'] = isset($webrequest['brand_id']) ? intval($webrequest['brand_id']) : 0;

			$tempnewsid = $db->Insert('news', '', TRUE);
			//删除站点公告缓存
			//cache_GetNotice($categoryDataModel, true);
			//cache_GetShowIndexNews($categoryDataModel, true);

			admin_AddLog("添加资讯|id: {$tempnewsid}; classid: {$webglobal['CPP']['news_category_id']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('资讯添加成功。', ADMIN_WEBURLPATH."/index.php?mode=content&root=".$webrequest['root']);
		}
	} else {
		$webglobal['file_news']['nowtime'] = global_FormatTime(time());
		if ($webrequest['root'] == 5) {
			//查询VIP咨询
			$webglobal['file_news']['brandinfo'] = array();
			$brandQuery = $db->Query("SELECT id, name FROM {$webconfig['dbpre']}brand_info WHERE status = 1");
			while ($row = $db->FetchArray($brandQuery)) {
				$webglobal['file_news']['brandinfo'][$row['id']] = $row;
			}
		}

		admin_StartFromForm();
	}

} elseif ($webglobal['mode'] == 'imageadd') {
	$webrequest['root'] = isset($webrequest['root']) ? intval($webrequest['root']) : 0;
	if (!$webrequest['root'] || !array_key_exists($webrequest['root'], $webconfig['newsTopType'])) {
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	$webglobal['file_news']['rootCategory'] = $categoryDataModel->getItem($webrequest['root']);

	//$webglobal['file_news']['channelName'] = $webglobal['file_news']['channeltype'][$webrequest['channel']];
	$webglobal['file_news']['class'] = $categoryDataModel->getCategoryOptionByChannel(2, $webrequest['root']);
	//$webglobal['file_news']['class'] = $categoryDataModel->formatCategoryOption($webrequest['root'], 0);
	//
	if (global_CheckSubmit('adminsubmit')) {
		global_CheckPost(
				array(
					array('news_category_id,','int','','请指定文档的栏目！',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM'])) {
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		} else {
			
			//admin_CheckFromForm(ADMIN_WEBURLPATH."/index.php?mode=news");
			//$category = $webglobal['file_news']['class'][$webglobal['CPD']['news_category_id']];

			if(!$categoryDataModel->checkChannel($webglobal['CPD']['news_category_id'], 2)) {
				admin_ShowMessage("你所选择的栏目与当前模型不相符，请选择白色的选项！", '', 'BACK');
				exit();
			}
			$webglobal['CPD']['flag'] = isset($webrequest['flags']) ? implode(',', $webrequest['flags']) : '';
			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);

			$webglobal['CPD']['edittime'] = $webserver['timestamp'];

			$webglobal['CPD']['title'] = preg_replace("#\"#", '＂', $webglobal['CPD']['title']);
			$webglobal['CPD']['title'] = global_CutStrR($webglobal['CPD']['title'], 100);
			if ($webrequest['shorttitle'] == '') {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['title'],36);
			} else {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['shorttitle'],36);
			}
			$webglobal['CPD']['color'] =  global_CutStrR($webrequest['color'],7);
			$webglobal['CPD']['writer'] =  global_CutStrR($webrequest['writer'],20);
			$webglobal['CPD']['from'] =  global_CutStrR($webrequest['from'],30);

			if ($webrequest['description'] == '') {
				//自动摘要
				$webglobal['CPD']['description'] = global_CutStr(SpHtml2Text($webglobal['CPD']['content']), 200);
				$webglobal['CPD']['description'] = trim(preg_replace('/#p#|#e#/','',$webglobal['CPD']['description']));
				$webglobal['CPD']['description'] = addslashes($webglobal['CPD']['description']);
			} else {
				$webglobal['CPD']['description'] =  global_CutStrR($webrequest['description'], 200);
			}
			$webglobal['CPD']['keywords'] =  global_CutStrR($webrequest['keywords'], 60);
			$webrequest['sortup'] = isset($webrequest['sortup']) ? intval($webrequest['sortup']) : 0;
			$webglobal['CPD']['sortrank'] = AddDay($webglobal['CPD']['showtime'], $webrequest['sortup']);
			$webglobal['CPD']['sortup'] = $webrequest['sortup'];
			$webglobal['CPD']['click'] = intval($webrequest['click']);
			$webglobal['CPD']['arcrank'] = intval($webrequest['arcrank']);
			if ($webrequest['picname'] != '') {
				$webglobal['CPD']['litpic'] = str_replace(WEBURLPATH, '', $webrequest['picname']);
			}

			$webglobal['CPD']['dutyadmin'] = $user['adminuid'];
			$webglobal['CPD']['channel'] = 2;
			$webglobal['CPD']['brand_id'] = isset($webrequest['brand_id']) ? intval($webrequest['brand_id']) : 0;
			//处理图集
			$imagevalue = array();
			$webrequest['picinfo'] = isset($webrequest['picinfo']) ? $webrequest['picinfo'] : array();
			$webrequest['filepath'] = isset($webrequest['filepath']) ? $webrequest['filepath'] : array();
			if ($webrequest['filepath']) {
				foreach ($webrequest['filepath'] as $num => $value) {
					if ($value) {
						$imagevalue[] = array(
							'info' => $webrequest['picinfo'][$num],
							'src'  => $value
						);
					}
				}
			}
			$webglobal['CPD']['imagevalue'] = serialize($imagevalue);

			$tempnewsid = $db->Insert('news', '', TRUE);
			//删除站点公告缓存
			//cache_GetNotice($categoryDataModel, true);
			//cache_GetShowIndexNews($categoryDataModel, true);

			admin_AddLog("添加资讯|id: {$tempnewsid}; classid: {$webglobal['CPP']['news_category_id']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('图集添加成功。', ADMIN_WEBURLPATH."/index.php?mode=content&root=".$webrequest['root']);
		}
	} else {
		if ($webrequest['root'] == 5) {
			//查询VIP咨询
			$webglobal['file_news']['brandinfo'] = array();
			$brandQuery = $db->Query("SELECT id, name FROM {$webconfig['dbpre']}brand_info WHERE status = 1");
			while ($row = $db->FetchArray($brandQuery)) {
				$webglobal['file_news']['brandinfo'][$row['id']] = $row;
			}
		}
		$webglobal['file_news']['nowtime'] = global_FormatTime(time());
		admin_StartFromForm();
	}

} elseif ($webglobal['mode'] == 'imageedit') {
	$webrequest['editid'] = isset($webrequest['editid']) ? intval($webrequest['editid']) : 0;
	if ($webrequest['editid'] <= 0) {
		admin_ShowMessage('不存在该图集。', '', 'BACK');
	}

	$webglobal['file_news']['editinfo'] = $db->GetOne("SELECT * FROM {$webconfig['dbpre']}news WHERE id='{$webrequest['editid']}'");
	if (!$webglobal['file_news']['editinfo']) {
		admin_ShowMessage('不存在该资讯。', '', 'BACK');
	}

	//$webglobal['file_news']['class'] = $categoryDataModel->getCategoryOptionByChannel(2, 0);
	$webglobal['file_news']['class'] = $categoryDataModel->formatCategoryOption(0, 0);

	if (global_CheckSubmit('adminsubmit')) {
		global_CheckPost(
				array(
					array('news_category_id,','int','','请指定文档的栏目！',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM'])) {
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		} else {
			/*
			if(!$categoryDataModel->checkChannel($webglobal['CPD']['news_category_id'], 2)) {
				admin_ShowMessage("你所选择的栏目与当前模型不相符，请选择白色的选项！", '', 'BACK');
				exit();
			}
			*/
			$webglobal['CPD']['flag'] = isset($webrequest['flags']) ? implode(',', $webrequest['flags']) : '';
			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);

			$webglobal['CPD']['edittime'] = $webserver['timestamp'];

			$webglobal['CPD']['title'] = preg_replace("#\"#", '＂', $webglobal['CPD']['title']);
			$webglobal['CPD']['title'] = global_CutStrR($webglobal['CPD']['title'], 100);
			if ($webrequest['shorttitle'] == '') {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['title'],36);
			} else {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['shorttitle'],36);
			}
			$webglobal['CPD']['color'] =  global_CutStrR($webrequest['color'],7);
			$webglobal['CPD']['writer'] =  global_CutStrR($webrequest['writer'],20);
			$webglobal['CPD']['from'] =  global_CutStrR($webrequest['from'],30);

			if ($webrequest['description'] == '') {
				//自动摘要
				$webglobal['CPD']['description'] = global_CutStr(SpHtml2Text($webglobal['CPD']['content']), 200);
				$webglobal['CPD']['description'] = trim(preg_replace('/#p#|#e#/','',$webglobal['CPD']['description']));
				$webglobal['CPD']['description'] = addslashes($webglobal['CPD']['description']);
			} else {
				$webglobal['CPD']['description'] =  global_CutStrR($webrequest['description'], 200);
			}
			$webglobal['CPD']['keywords'] =  global_CutStrR($webrequest['keywords'], 60);

			$webrequest['sortup'] = isset($webrequest['sortup']) ? intval($webrequest['sortup']) : 0;
			$webglobal['CPD']['sortrank'] = AddDay($webglobal['CPD']['showtime'], $webrequest['sortup']);
			$webglobal['CPD']['sortup'] = $webrequest['sortup'];
			$webglobal['CPD']['click'] = intval($webrequest['click']);
			$webglobal['CPD']['arcrank'] = intval($webrequest['arcrank']);
			if ($webrequest['picname'] != '') {
				$webglobal['CPD']['litpic'] = str_replace(WEBURLPATH, '', $webrequest['picname']);
			}

			$webglobal['CPD']['dutyadmin'] = $user['adminuid'];
			$webglobal['CPD']['channel'] = 2;
			$webglobal['CPD']['brand_id'] = isset($webrequest['brand_id']) ? intval($webrequest['brand_id']) : 0;
			//处理图集
			$imagevalue = array();
			$webrequest['picinfo'] = isset($webrequest['picinfo']) ? $webrequest['picinfo'] : array();
			$webrequest['filepath'] = isset($webrequest['filepath']) ? $webrequest['filepath'] : array();
			if ($webrequest['filepath']) {
				foreach ($webrequest['filepath'] as $num => $value) {
					if ($value) {
						$imagevalue[] = array(
							'info' => $webrequest['picinfo'][$num],
							'src'  => $value
						);
					}
				}
			}
			$webglobal['CPD']['imagevalue'] = serialize($imagevalue);
			$db->Update('news', '', "id='{$webrequest['editid']}'");
			//删除站点公告缓存
			//cache_GetNotice($categoryDataModel, true);
			//cache_GetShowIndexNews($categoryDataModel, true);

			admin_AddLog("修改资讯|id: {$webrequest['editid']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('资讯修改成功。', ADMIN_WEBURLPATH."/index.php?mode=content&{$webrequest['gourl']}");
		}
	} else {
		$webglobal['file_news']['gourlencode'] = urlencode($webrequest['gourl']);
		$webglobal['file_news']['gourl'] = urldecode($webrequest['gourl']);
		$webglobal['file_news']['editinfo']['showtime_show'] = global_FormatTime($webglobal['file_news']['editinfo']['showtime']);
		if (!$webglobal['file_news']['editinfo']['imagevalue'] = @unserialize($webglobal['file_news']['editinfo']['imagevalue'])) {
			$webglobal['file_news']['editinfo']['imagevalue'] = array();
		}

		if ($webrequest['root'] == 5) {
			//查询VIP咨询
			$webglobal['file_news']['brandinfo'] = array();
			$brandQuery = $db->Query("SELECT id, name FROM {$webconfig['dbpre']}brand_info WHERE status = 1");
			while ($row = $db->FetchArray($brandQuery)) {
				$webglobal['file_news']['brandinfo'][$row['id']] = $row;
			}
		}
		admin_StartFromForm();
	}
} elseif ($webglobal['mode']=='contentedit') {
	$webrequest['editid'] = isset($webrequest['editid']) ? intval($webrequest['editid']) : 0;
	if ($webrequest['editid'] <= 0) {
		admin_ShowMessage('不存在该资讯。', '', 'BACK');
	}

	$webglobal['file_news']['editinfo'] = $db->GetOne("SELECT * FROM {$webconfig['dbpre']}news WHERE id='{$webrequest['editid']}'");
	if (!$webglobal['file_news']['editinfo']) {
		admin_ShowMessage('不存在该资讯。', '', 'BACK');
	}

	$webglobal['file_news']['class'] = $categoryDataModel->formatCategoryOption(0);

	if (global_CheckSubmit('adminsubmit')) {
		global_CheckPost(
				array(
					array('news_category_id,','int','','请指定文档的栏目！',1),
					array('title,','str','','标题不能为空',1),
					array('from,','str','','',0,''),
					array('showtime','date','','显示时间必须为日期格式'),
					array('content,','','','内容不能为空',1),
			));
		if (!empty($webglobal['CPM'])) {
			admin_ShowMessage($webglobal['CPM'], '', 'BACK');
		} else {
			/*
			if(!$categoryDataModel->checkChannel($webglobal['CPD']['news_category_id'], 1)) {
				admin_ShowMessage("你所选择的栏目与当前模型不相符，请选择白色的选项！", '', 'BACK');
				exit();
			}
			*/
			$webglobal['CPD']['flag'] = isset($webrequest['flags']) ? implode(',', $webrequest['flags']) : '';
			$webglobal['CPD']['showtime'] = empty($webglobal['CPP']['showtime']) ? $webserver['timestamp'] : global_ConvTime($webglobal['CPP']['showtime']);

			$webglobal['CPD']['edittime'] = $webserver['timestamp'];

			$webglobal['CPD']['title'] = preg_replace("#\"#", '＂', $webglobal['CPD']['title']);
			$webglobal['CPD']['title'] = global_CutStrR($webglobal['CPD']['title'], 100);
			if ($webrequest['shorttitle'] == '') {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['title'],36);
			} else {
				$webglobal['CPD']['shorttitle'] = global_CutStrR($webrequest['shorttitle'],36);
			}
			
			$webglobal['CPD']['color'] =  global_CutStrR($webrequest['color'],7);
			$webglobal['CPD']['writer'] =  global_CutStrR($webrequest['writer'],20);
			$webglobal['CPD']['from'] =  global_CutStrR($webrequest['from'],30);

			if ($webrequest['description'] == '') {
				//自动摘要
				$webglobal['CPD']['description'] = global_CutStr(SpHtml2Text($webglobal['CPD']['content']), 200);
				$webglobal['CPD']['description'] = trim(preg_replace('/#p#|#e#/','',$webglobal['CPD']['description']));
				$webglobal['CPD']['description'] = addslashes($webglobal['CPD']['description']);
			} else {
				$webglobal['CPD']['description'] =  global_CutStrR($webrequest['description'], 200);
			}
			$webglobal['CPD']['keywords'] =  global_CutStrR($webrequest['keywords'], 60);

			$webrequest['sortup'] = isset($webrequest['sortup']) ? intval($webrequest['sortup']) : 0;
			$webglobal['CPD']['sortrank'] = AddDay($webglobal['CPD']['showtime'], $webrequest['sortup']);
			$webglobal['CPD']['sortup'] = $webrequest['sortup'];
			$webglobal['CPD']['click'] = intval($webrequest['click']);
			$webglobal['CPD']['arcrank'] = intval($webrequest['arcrank']);
			if ($webrequest['picname'] != '') {
				$webglobal['CPD']['litpic'] = str_replace(WEBURLPATH, '', $webrequest['picname']);
			}
			$webglobal['CPD']['dutyadmin'] = $user['adminuid'];
			$webglobal['CPD']['channel'] = 1;
			$webglobal['CPD']['brand_id'] = isset($webrequest['brand_id']) ? intval($webrequest['brand_id']) : 0;

			$db->Update('news', '', "id='{$webrequest['editid']}'");
			//删除站点公告缓存
			//cache_GetNotice($categoryDataModel, true);
			//cache_GetShowIndexNews($categoryDataModel, true);

			admin_AddLog("修改资讯|id: {$webrequest['editid']}; title: {$webglobal['CPP']['title']}");
			admin_ShowMessage('资讯修改成功。', ADMIN_WEBURLPATH."/index.php?mode=content&{$webrequest['gourl']}");
		}
	} else {
		$webglobal['file_news']['gourlencode'] = urlencode($webrequest['gourl']);
		$webglobal['file_news']['gourl'] = urldecode($webrequest['gourl']);
		$webglobal['file_news']['editinfo']['showtime_show'] = global_FormatTime($webglobal['file_news']['editinfo']['showtime']);

		if ($webrequest['root'] == 5) {
			//查询VIP咨询
			$webglobal['file_news']['brandinfo'] = array();
			$brandQuery = $db->Query("SELECT id, name FROM {$webconfig['dbpre']}brand_info WHERE status = 1");
			while ($row = $db->FetchArray($brandQuery)) {
				$webglobal['file_news']['brandinfo'][$row['id']] = $row;
			}
		}

		admin_StartFromForm();
	}
} elseif ($webglobal['mode']=='delete') {
	
} elseif ($webglobal['mode']=='content') {
	//$webrequest['channel'] = isset($webrequest['channel']) ? intval($webrequest['channel']) : 0;
	$webrequest['root'] = isset($webrequest['root']) ? intval($webrequest['root']) : 0;
	if (!$webrequest['root'] || !array_key_exists($webrequest['root'], $webconfig['newsTopType'])) {
		admin_ShowMessage('参数错误。', '', 'BACK');
	}

	$webglobal['file_news']['rootCategory'] = $categoryDataModel->getItem($webrequest['root']);

	$webglobal['file_news']['class'] = $categoryDataModel->formatCategoryOption($webrequest['root'], 0);

	$webrequest['order'] = isset($webrequest['order']) ? trim($webrequest['order']) : '';
	$webrequest['class'] = isset($webrequest['class']) ? intval($webrequest['class']) : 0;
	$webrequest['arcrank'] = isset($webrequest['arcrank']) ? intval($webrequest['arcrank']) : -2;
	$webrequest['searchkey'] = isset($webrequest['searchkey']) ? $webrequest['searchkey'] : '';
	
	$allChildCategory = array_keys($webglobal['file_news']['class']);
	$tempsearchsql = 'news_category_id IN ('.implode(',', $allChildCategory).')';

	if ($webrequest['searchkey']!='' || $webrequest['class']>0 || $webrequest['arcrank'] > -2)
	{
		$tempsearchsql = $db->BuildSearchSql($webrequest['searchkey'], array('title', 'shorttitle', 'description'));
		if ($webrequest['class'] > 0)
		{
			$tempsearchsql .= (($tempsearchsql!='') ? ' AND ' : '')."news_category_id='{$webrequest['class']}'";
		}
		if ($webrequest['arcrank'] > -2) {
			$tempsearchsql .= (($tempsearchsql!='') ? ' AND ' : '')."arcrank='{$webrequest['arcrank']}'";
		}
	}
	$tempsearchsql = " WHERE {$tempsearchsql}";

	$webglobal['file_news']['gourl'] = "page={$webrequest['page']}&root=".$webrequest['root'];
	$webglobal['file_news']['pageurl'] = "root=".$webrequest['root'];
	if ($webrequest['order'] != '')
	{
		$webglobal['file_news']['gourl'] .= "&order={$webrequest['order']}";
	}
	if ($webrequest['class'] > 0)
	{
		$webglobal['file_news']['gourl'] .= "&class={$webrequest['class']}";
		$webglobal['file_news']['pageurl'] .= "&class={$webrequest['class']}";
	}
	if ($webrequest['arcrank'] > -2) {
		$webglobal['file_news']['gourl'] .= "&arcrank={$webrequest['arcrank']}";
		$webglobal['file_news']['pageurl'] .= "&arcrank={$webrequest['arcrank']}";
	}
	if ($webrequest['searchkey'] != '')
	{
		$webglobal['file_news']['gourl'] .= "&searchkey=".urlencode($webrequest['searchkey']);
		$webglobal['file_news']['pageurl'] .= "&searchkey=".urlencode($webrequest['searchkey']);
	}
	$webglobal['file_news']['gourlencode'] = urlencode($webglobal['file_news']['gourl']);

	$webglobal['file_news']['perpage'] = 15;
	$webglobal['file_news']['datanum'] = $db->GetNum("SELECT COUNT(*) FROM {$webconfig['dbpre']}news{$tempsearchsql}");
	if ($webglobal['file_news']['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['file_news']['datanum'], $webglobal['file_news']['perpage'], $webrequest['page'], ADMIN_WEBURLPATH."/index.php?mode=news&order={$webrequest['order']}{$webglobal['file_news']['pageurl']}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['file_news']['perpage'];
		switch ($webrequest['order'])
		{
			case 'id':
				$temporderstr = "id DESC";
				break;
			case 'showtime':
				$temporderstr = "showtime DESC,id DESC";
				break;
			case 'edittime':
				$temporderstr = "edittime DESC";
				break;
			case 'weight':
				$temporderstr = "`weight` DESC,id DESC";
				break;
			case 'index':
				$temporderstr = "`index` DESC,id DESC";
				break;
			case 'ishot':
				$temporderstr = "`ishot` DESC,id DESC";
				break;
			default:
				$temporderstr = "`weight` DESC,showtime DESC,id DESC";
		}
		$query = $db->Query("SELECT * FROM {$webconfig['dbpre']}news{$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['file_news']['perpage']}");
		$temptr = 1;
		$webglobal['file_news']['dataarray'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['tdclass'] = (($temptr++)%2==0) ? ' class="evenrow"' : '';
			$tempdata['showtime_show'] = global_FormatTime($tempdata['showtime'], 'FD');
			$tempdata['edittime_show'] = global_FormatTime($tempdata['edittime'], 'FD');
			$webglobal['file_news']['dataarray'][$tempdata['id']] = $tempdata;
		}
	}
//列表
} elseif ($webglobal['mode']=='news') {
	$webrequest['order'] = isset($webrequest['order']) ? trim($webrequest['order']) : '';
	$webrequest['class'] = isset($webrequest['class']) ? intval($webrequest['class']) : 0;
	$webrequest['searchkey'] = isset($webrequest['searchkey']) ? $webrequest['searchkey'] : '';
	
	$tempsearchsql = '';
	if ($webrequest['searchkey']!='' || $webrequest['class']>0)
	{
		$tempsearchsql = $db->BuildSearchSql($webrequest['searchkey'], array('title'));
		if ($webrequest['class'] > 0)
		{
			$tempsearchsql .= (($tempsearchsql!='') ? ' AND ' : '')."news_category_id='{$webrequest['class']}'";
		}
		$tempsearchsql = " WHERE {$tempsearchsql}";
	}

	$webglobal['file_news']['gourl'] = "page={$webrequest['page']}";
	$webglobal['file_news']['pageurl'] = "";
	if ($webrequest['order'] != '')
	{
		$webglobal['file_news']['gourl'] .= "&order={$webrequest['order']}";
	}
	if ($webrequest['class'] > 0)
	{
		$webglobal['file_news']['gourl'] .= "&class={$webrequest['class']}";
		$webglobal['file_news']['pageurl'] .= "&class={$webrequest['class']}";
	}
	if ($webrequest['searchkey'] != '')
	{
		$webglobal['file_news']['gourl'] .= "&searchkey=".urlencode($webrequest['searchkey']);
		$webglobal['file_news']['pageurl'] .= "&searchkey=".urlencode($webrequest['searchkey']);
	}
	$webglobal['file_news']['gourlencode'] = urlencode($webglobal['file_news']['gourl']);

	$webglobal['file_news']['perpage'] = 15;
	$webglobal['file_news']['datanum'] = $db->GetNum("SELECT COUNT(*) FROM {$webconfig['dbpre']}news{$tempsearchsql}");
	if ($webglobal['file_news']['datanum'] > 0)
	{
		$webglobal['page'] = global_Page($webglobal['file_news']['datanum'], $webglobal['file_news']['perpage'], $webrequest['page'], ADMIN_WEBURLPATH."/index.php?mode=news&order={$webrequest['order']}{$webglobal['file_news']['pageurl']}&page=@@");
		$tempstartnum = ($webrequest['page']-1)*$webglobal['file_news']['perpage'];
		switch ($webrequest['order'])
		{
			case 'id':
				$temporderstr = "id DESC";
				break;
			case 'showtime':
				$temporderstr = "showtime DESC,id DESC";
				break;
			case 'edittime':
				$temporderstr = "edittime DESC";
				break;
			case 'weight':
				$temporderstr = "`weight` DESC,id DESC";
				break;
			case 'index':
				$temporderstr = "`index` DESC,id DESC";
				break;
			case 'ishot':
				$temporderstr = "`ishot` DESC,id DESC";
				break;
			default:
				$temporderstr = "`weight` DESC,showtime DESC,id DESC";
		}
		$query = $db->Query("SELECT * FROM {$webconfig['dbpre']}news{$tempsearchsql} ORDER BY {$temporderstr} LIMIT $tempstartnum, {$webglobal['file_news']['perpage']}");
		$temptr = 1;
		$webglobal['file_news']['dataarray'] = array();
		while ($tempdata = $db->FetchArray($query))
		{
			$tempdata['tdclass'] = (($temptr++)%2==0) ? ' class="evenrow"' : '';
			$tempdata['showtime_show'] = global_FormatTime($tempdata['showtime'], 'FD');
			$tempdata['edittime_show'] = global_FormatTime($tempdata['edittime']);
			$webglobal['file_news']['dataarray'][$tempdata['id']] = $tempdata;
		}
	}
}

if (in_array($webglobal['mode'], array('content', 'contentadd', 'contentedit'))) {
	template_Display('content', 1);
} elseif (in_array($webglobal['mode'], array('imagecut', 'imageadd', 'imageedit'))) {
	template_Display('content_1', 1);
} else {
	template_Display('news', 1);
}